gdk_window_create_similar_image_surface
gdk_cairo_create
gdk_cairo_get_clip_rectangle
-gdk_cairo_get_window
+gdk_cairo_get_drawing_context
gdk_cairo_set_source_color
gdk_cairo_set_source_rgba
gdk_cairo_set_source_pixbuf
#include <gdk/gdkversionmacros.h>
#include <gdk/deprecated/gdkcolor.h>
#include <gdk/gdkrgba.h>
+#include <gdk/gdkdrawingcontext.h>
#include <gdk/gdkpixbuf.h>
#include <pango/pangocairo.h>
GDK_AVAILABLE_IN_ALL
cairo_t * gdk_cairo_create (GdkWindow *window);
-GDK_AVAILABLE_IN_3_22
-GdkWindow * gdk_cairo_get_window (cairo_t *cr);
+
GDK_AVAILABLE_IN_ALL
gboolean gdk_cairo_get_clip_rectangle (cairo_t *cr,
GdkRectangle *rect);
int width,
int height);
+GDK_AVAILABLE_IN_3_22
+GdkDrawingContext * gdk_cairo_get_drawing_context (cairo_t *cr);
G_END_DECLS
{
}
+static const cairo_user_data_key_t draw_context_key;
+
+static void
+gdk_cairo_set_drawing_context (cairo_t *cr,
+ GdkDrawingContext *context)
+{
+ cairo_set_user_data (cr, &draw_context_key, context, NULL);
+}
+
+/**
+ * gdk_cairo_get_drawing_context:
+ * @cr: a Cairo context
+ *
+ * Retrieves the #GdkDrawingContext that created the Cairo
+ * context @cr.
+ *
+ * Returns: (transfer none) (nullable): a #GdkDrawingContext, if any is set
+ *
+ * Since: 3.22
+ */
+GdkDrawingContext *
+gdk_cairo_get_drawing_context (cairo_t *cr)
+{
+ g_return_val_if_fail (cr != NULL, NULL);
+
+ return cairo_get_user_data (cr, &draw_context_key);
+}
+
/**
* gdk_drawing_context_get_cairo_context:
* @context:
if (context->cr == NULL)
{
context->cr = gdk_cairo_create (context->window);
+
+ gdk_cairo_set_drawing_context (context->cr, context);
+
gdk_cairo_region (context->cr, context->clip);
cairo_clip (context->cr);
}
gdk_window_begin_paint_internal (window, region);
}
-static const cairo_user_data_key_t draw_context_window_key;
-
-static void
-gdk_cairo_set_window (cairo_t *cr,
- GdkWindow *window)
-{
- cairo_set_user_data (cr, &draw_context_window_key, window, NULL);
-}
-
-/**
- * gdk_cairo_get_window:
- * @cr: a Cairo context created by gdk_window_begin_draw_frame()
- *
- * Retrieves the #GdkWindow that created the Cairo context @cr.
- *
- * Returns: (nullable) (transfer none): a #GdkWindow
- *
- * Since: 3.22
- */
-GdkWindow *
-gdk_cairo_get_window (cairo_t *cr)
-{
- g_return_val_if_fail (cr != NULL, NULL);
-
- return cairo_get_user_data (cr, &draw_context_window_key);
-}
-
/**
* gdk_window_begin_draw_frame:
* @window: a #GdkWindow
cr = cairo_create (surface);
- gdk_cairo_set_window (cr, window);
-
if (window->impl_window->current_paint.region != NULL)
{
region = cairo_region_copy (window->impl_window->current_paint.region);
gtk_cairo_should_draw_window (cairo_t *cr,
GdkWindow *window)
{
+ GdkDrawingContext *context;
GdkWindow *tmp;
g_return_val_if_fail (cr != NULL, FALSE);
if (gtk_cairo_is_marked_for_draw (cr))
return TRUE;
- tmp = gdk_cairo_get_window (cr);
+ context = gdk_cairo_get_drawing_context (cr);
+ if (context == NULL)
+ return TRUE;
+ tmp = gdk_drawing_context_get_window (context);
if (tmp == NULL)
return TRUE;
if (gdk_cairo_get_clip_rectangle (cr, NULL))
{
- GdkWindow *event_window;
+ GdkWindow *event_window = NULL;
gboolean result;
gboolean push_group;
/* If this was a cairo_t passed via gtk_widget_draw() then we don't
- * require a window
+ * require a window; otherwise we check for the window associated
+ * to the drawing context and mark it using the clip region of the
+ * Cairo context.
*/
- if (gtk_cairo_is_marked_for_draw (cr))
- {
- event_window = NULL;
- }
- else
+ if (!gtk_cairo_is_marked_for_draw (cr))
{
- event_window = gdk_cairo_get_window (cr);
- if (event_window != NULL)
- gdk_window_mark_paint_from_clip (event_window, cr);
+ GdkDrawingContext *context = gdk_cairo_get_drawing_context (cr);
+
+ if (context != NULL)
+ {
+ event_window = gdk_drawing_context_get_window (context);
+ if (event_window != NULL)
+ gdk_window_mark_paint_from_clip (event_window, cr);
+ }
}
push_group =